package com.shimba.recording.universalinterface;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.shimba.recording.universalinterface.nblinterface.FunctionManager;
import com.shimba.recording.universalinterface.nblinterface.FunctionNoParamHasResult;
import com.shimba.recording.universalinterface.nblinterface.FunctionNoParamNoResult;

import java.util.ArrayList;

public class MainActivity extends FragmentActivity {
    private ViewPager mViewPager;
    private ArrayList<Fragment> fragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViewPager = findViewById(R.id.view_pager);
        initData();
        initFunction();
    }

    private void initFunction() {
        //无参，无返回
        FunctionManager.getInstance().addFunction(new FunctionNoParamNoResult("noParamNoResult") {
            @Override
            public void function() {
                Log.e("===>Main", "这个方法没有返回值也没有参数，但是被调用了。");
            }
        });
        //无参又返回值的
        FunctionManager.getInstance().addFunction(new FunctionNoParamHasResult<String>("noParamHasResult") {
            @Override
            public String function() {
                return "Hell from the MainActivity";
            }
        });
    }

    private void initData() {
        fragments = new ArrayList<>();
        FragmentOne fragmentOne = new FragmentOne();
        fragments.add(fragmentOne);
        FragmentTow fragmentTow = new FragmentTow();
        fragments.add(fragmentTow);
        FragmentThree fragmentThree = new FragmentThree();
        fragments.add(fragmentThree);


        FragmentAdapter fragmentPagerAdapter = new FragmentAdapter(getSupportFragmentManager());
        fragmentPagerAdapter.setData(fragments);
        mViewPager.setAdapter(fragmentPagerAdapter);
    }


}
